# Maintainer: Felix Yan <felixonmars@archlinux.org>
# Contributor: Sergej Pupykin <pupykin.s+arch@gmail.com>
# Contributor: Tinxy <arch at tinx dot eu>

pkgname=hedgewars
pkgver=1.0.2
pkgrel=21
pkgdesc="Turn-based strategy artillery game similiar to Worms"
arch=('loong64' 'x86_64')
url="https://hedgewars.org"
license=('GPL' 'custom')
depends=('qt5-base' 'sdl2' 'sdl2_mixer' 'sdl2_image' 'sdl2_net' 'sdl2_ttf' 'lua51' 'ffmpeg4.4' 'glut'
         'physfs' 'ghc-libs' 'haskell-entropy' 'haskell-sha' 'haskell-random' 'haskell-regex-tdfa'
         'haskell-sandi' 'haskell-hslogger' 'haskell-network' 'haskell-network-bsd'
         'haskell-utf8-string' 'haskell-vector')
makedepends=('fpc' 'cmake' 'qt5-tools' 'ghc' 'haskell-bytestring-show' 'haskell-zlib'
             'haskell-base-prelude' 'imagemagick' 'mesa')
source=("https://www.hedgewars.org/download/releases/hedgewars-src-$pkgver.tar.bz2")
sha512sums=('dc79cc48eee305d8dd2b64fcbfe598d48f8aec918d9065a6af4aef9be4e4940ad858836fc6bda46e02128b80dbba8c443a4f8a702a16b0ac969f8d0a0e080502')

prepare() {
  cd hedgewars-src-$pkgver
  sed -i 's|set(ghc_flags|set(ghc_flags -dynamic|' gameServer/CMakeLists.txt
}

build() {
  cd hedgewars-src-$pkgver
  export PKG_CONFIG_PATH='/usr/lib/ffmpeg4.4/pkgconfig'
  cmake \
    -Bbuild \
    -DCMAKE_BUILD_TYPE="Release" \
    -DCMAKE_INSTALL_PREFIX=/usr \
    -DDATA_INSTALL_DIR=/usr/share/hedgewars \
    -DNOSERVER=0
  make -C build

  # resize icon
  for _size in 16 32 48 64 128 256; do
    convert +set date:create +set date:modify misc/hedgewars.png -resize ${_size}x${_size} hedgewars_${_size}.png
  done
}

package() {
  cd hedgewars-src-$pkgver
  DESTDIR="$pkgdir" make -C build install
  install -D -m644 Fonts_LICENSE.txt "$pkgdir"/usr/share/licenses/${pkgname}/Fonts_LICENSE.txt

  # install icons
  install -D -m644 misc/hedgewars.png "$pkgdir"/usr/share/icons/hicolor/512x512/apps/hedgewars.png
  for _size in 16 32 48 64 128 256; do
    install -D -m644 hedgewars_${_size}.png "$pkgdir"/usr/share/icons/hicolor/${_size}x${_size}/apps/hedgewars.png
  done
  rm -rf "$pkgdir"/usr/share/pixmaps

  install -D -m644 share/hedgewars/Data/misc/hedgewars.desktop "$pkgdir"/usr/share/applications/hedgewars.desktop
}
